﻿using System;
using System.Collections.Generic;
using System.Text;
using WeShare.WeiXin.Common;
using WeShare.WeiXin.Common.EnumKey;

namespace WeShare.WeiXin.Mp.JsSdk.Entity
{
    public class ChooseCardParam
    {
        private ChooseCardParam() { }

        public ChooseCardParam(string appId,string shopId = "", CardType? cardType = null, string cardId = "")
        {
            this.shopId = shopId;
            this.cardType = cardType;
            this.cardId = cardId;
            var ticket = ApiTicket.GetValue(TicketType.wx_card, appId);
            var arr = new string[] { ticket, appId, shopId, this.timestamp.ToString(), this.nonceStr, cardId, cardType == null ? "" : cardType.ToString() };
            //字典排序
            Array.Sort(arr);
            //使用URL键值对的格式拼接成字符串
            var temp = string.Join("", arr);
            this.cardSign = Utils.Sha1(temp);
        }
        /// <summary>
        ///门店ID。shopID用于筛选出拉起带有指定location_list(shopID)的卡券列表，非必填。
        /// </summary>
        public string shopId { get; set; }
        /// <summary>
        ///卡券类型，用于拉起指定卡券类型的卡券列表。当cardType为空时，默认拉起所有卡券的列表，非必填。
        /// </summary>
        public CardType? cardType { get; set; }
        /// <summary>
        /// 卡券ID，用于拉起指定cardId的卡券列表，当cardId为空时，默认拉起所有卡券的列表，非必填。
        /// </summary>
        public string cardId { get; set; }
        /// <summary>
        /// 	时间戳。
        /// </summary>
        public long timestamp { get; set; } = Utils.GetTimeStamp();
        /// <summary>
        /// 	随机字符串。
        /// </summary>
        public string nonceStr { get; set; } = Utils.GetTimeStamp().ToString();

        /// <summary>
        /// 签名方式，目前仅支持SHA1
        /// </summary>
        public string signType { get; set; } = "SHA1";
        public string cardSign { get; set; }
    }
}
